package br.mil.eb.pqrmnt7.scc.entity;

import java.util.Date;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import org.apache.myfaces.extensions.validator.crossval.annotation.RequiredIfType;
import javax.persistence.TemporalType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.GenerationType;
import org.hibernate.annotations.ForeignKey;
import com.powerlogic.jcompany.domain.validation.PlcValGroupEntityList;
import org.apache.myfaces.extensions.validator.crossval.annotation.RequiredIf;
import javax.persistence.Temporal;
import javax.validation.constraints.Size;
import javax.persistence.FetchType;
import javax.validation.constraints.Digits;
import com.powerlogic.jcompany.config.domain.PlcReference;
import javax.persistence.GeneratedValue;

@MappedSuperclass
public abstract class MedicaoOdometro extends AppBaseEntity {
	
	@Id 
 	@GeneratedValue(strategy=GenerationType.AUTO, generator = "SE_MEDICAO_ODOMETRO")
	private Long id;
	
	@NotNull(groups=PlcValGroupEntityList.class)
	@RequiredIf(valueOf="descricao",is=RequiredIfType.not_empty)
	@Digits(integer=10, fraction=0)
	private Long valor;
	
	@NotNull(groups=PlcValGroupEntityList.class)
	@RequiredIf(valueOf="descricao",is=RequiredIfType.not_empty)
	@Temporal(TemporalType.TIMESTAMP)
	private Date data;
	
	@NotNull(groups=PlcValGroupEntityList.class)
	@RequiredIf(valueOf="id",is=RequiredIfType.not_empty)
	@Size(max = 100)
	@PlcReference(testDuplicity=true)
	private String descricao;
	
	@ManyToOne (targetEntity = ViaturaEntity.class, fetch = FetchType.LAZY)
	@ForeignKey(name="FK_MEDICAOODOMETRO_VIATURA")
	@NotNull(groups=PlcValGroupEntityList.class)
	@RequiredIf(valueOf="descricao",is=RequiredIfType.not_empty)
	private Viatura viatura;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id=id;
	}

	public Long getValor() {
		return valor;
	}

	public void setValor(Long valor) {
		this.valor=valor;
	}

	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data=data;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao=descricao;
	}

	public Viatura getViatura() {
		return viatura;
	}

	public void setViatura(Viatura viatura) {
		this.viatura=viatura;
	}

}
